package ged.diagram.edit.parts;

import ged.diagram.part.MultiPageEditorPlugInDiagramEditor;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

public abstract class AbstractGedDiagramEditorPage extends EditorPart {
	
    /** the parent multi page editor */
    private final MultiPageEditorPlugInDiagramEditor parent;

    /** the edit domain */
    private final EditDomain domain;
	
    public AbstractGedDiagramEditorPage(MultiPageEditorPlugInDiagramEditor parent, EditDomain domain)
    {
        super();
        this.parent = parent;
        this.domain = domain;
    }
    
    public final void doSave(IProgressMonitor monitor)
    {
        // our policy: delegate saving to the parent
        getMultiPageEditorPlugInDiagramEditor().doSave(monitor);
    }
    
    public final void doSaveAs()
    {
        // our policy: delegate saving to the parent
    	getMultiPageEditorPlugInDiagramEditor().doSaveAs();
    }
    
/*    public void gotoMarker(IMarker marker)
    {
        // not necessary to implement, is handled by the multiPage editor
    }*/
    
    public void init(IEditorSite site, IEditorInput input)
            throws PartInitException
        {    	    
            setSite(site);
            setInput(input);
            setPartName(input.getName() + ": " + getPageName());
        }
    
    public final boolean isDirty()
    {
        // our policy: delegate saving to the parent
        // note: this method shouldn't get called anyway
        return getMultiPageEditorPlugInDiagramEditor().isDirty();
    }
    
    /**
     * Returns the <code>CommandStack</code> of this editor page.
     * @return the <code>CommandStack</code> of this editor page
     */
    protected final CommandStack getCommandStack()
    {
        return getEditDomain().getCommandStack();
    }
    
    /**
     * Returns the human readable name of this editor page.
     * @return the human readable name of this editor page
     */
    protected abstract String getPageName();
    
    /**
     * Returns the multi page MultiPageEditorPlugInDiagramEditor editor this editor page is contained in.
     * @return the parent multi page editor
     */
    protected final MultiPageEditorPlugInDiagramEditor getMultiPageEditorPlugInDiagramEditor()
    {
        return parent;
    }
    
    /**
     * Returns the edit domain this editor page uses.
     * @return the edit domain this editor page uses
     */
    public final EditDomain getEditDomain()
    {
        return domain;
    }

}
